package com.itheima.case1;

import java.util.ArrayList;
import java.util.Collections;

public class Case7Runnable implements Runnable{

    ArrayList<Integer> array ;

    public Case7Runnable(ArrayList array){
        this.array = array;
    }

    @Override
    public void run() {
        ArrayList<Integer> list = new ArrayList();

        while(true){
            synchronized (Case7Runnable.class){

                if(array.size() != 0){
                    Collections.shuffle(array);
                        list.add(array.remove(0));
                }else{
                    Integer max = 0;
                    Integer sum = 0;
                    for (Integer li : list) {
                        if(li > max){
                            max = li;
                            sum = sum+li;
                        }
                    }
                        System.out.println(Thread.currentThread().getName()+":"+list+";其中最大抽奖金额是："+max+"元人民币;总计抽中："+sum+"元");

                    break;
                }
            }
        }


    }
}
